package com.tz.online.cart;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.entity.Cart;

/**
 * 接收用户修改购物的请求
 * @author Administrator
 *
 */
@WebServlet(name="modifyCart",urlPatterns="/cart/modifyCart")
public class ModifyCartAction extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -5335729540554639096L;

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		
		try {
			String bookId = req.getParameter("bookId"); //接收商品ID ，
			String count = req.getParameter("count");// 接收修改数量
			//拿到session中购物车
			Cart cart = (Cart) req.getSession().getAttribute("cart");
			cart.modifyCart(bookId, count); //调用购物车中修改逻辑
			out.print("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			out.print("0");
			e.printStackTrace();
		}
		/*
		//接收ID和数量
		try {
			String bid = null;
			String count = null;
			
			Cart cart = (Cart) req.getSession().getAttribute("cart");
			
			cart.modifyCart(bid,count);
			req.getSession().setAttribute("cart", cart);
			
			out.print("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			out.print("0");
			e.printStackTrace();
		}
		*/
	}
	
}
